﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using OgilvyOne.BLL;
using System.Data;

public partial class allergy_doctor_doctor_online : System.Web.UI.Page
{
    protected int pnum = 0;
    protected int pageCount = 0;
    protected int total;
    protected string type;

    protected void Page_Load(object sender, EventArgs e)
    {

        //this.doctor_rpt.DataSource = BLLArticleInfo.getLiveDocrot();
        //this.doctor_rpt.DataBind();
        

        //专家博客
        this.right_rpt.DataSource = BLLArticleInfo.getFaqBlog();
        this.right_rpt.DataBind();

        //最新问答推荐
        this.recommend_rpt.DataSource = BLLArticleInfo.getRecommendFAQ();
        this.recommend_rpt.DataBind();

        //妈妈要知道
        this.doKnow_rpt.DataSource = BLLArticleInfo.selectc("5", "doKnow", "1");
        this.doKnow_rpt.DataBind();

        total = BLLArticleInfo.countFAQ();
        if ((total % 15) == 0)
        {
            pageCount = total / 15;
        }
        else
        {
            pageCount = (total / 15) + 1;
        }
        PagerControl1.LoadData = new LoadDataHandler(this.LoadPagingArticle);
        PagerControl1.GetPagerUrl = new GetPagerUrlHandler(this.GetPagerUrl);
        int pnum = 0;
        if (Request.Params["pnum"] != null || Request.Params["pnum"] != "")
            pnum = Convert.ToInt32(Request.Params["pnum"]);
        
        if (!IsPostBack)
        {
            //loadArticle();
            PagerControl1.LoadData = new LoadDataHandler(this.LoadPagingArticle);
            PagerControl1.PagingParams.TotalCount = total;
            PagerControl1.PagingParams.PageSize = 15;
            PagerControl1.PagingParams.CurrentPageIndex = pnum;
            LoadPagingArticle(PagerControl1.PagingParams);
        }

    }

    protected void LoadPagingArticle(PagingParameter pagingParams)
    {
        DataTable dt = BLLArticleInfo.GetFAQlist(pagingParams.PageSize.ToString(), (pagingParams.CurrentPageIndex * 15).ToString());
        this.question_rpt.DataSource = dt;
        this.question_rpt.DataBind();
    }

    //protected void page_Command(object sender, CommandEventArgs e)
    //{
    //    if (ViewState["pageNum"] != null)
    //    {
    //        pageNum = Convert.ToInt32(ViewState["pageNum"].ToString());
    //    }
    //    if (e.CommandName.Equals("next") || e.CommandName.Equals("nextp"))
    //    {
    //        pageNum++;
    //        if (pageNum > 1 && pageNum <= pageCount)
    //        {
    //            ViewState["pageNum"] = pageNum;
    //            loadArticle();
    //        }
    //    }
    //    else
    //    {
    //        pageNum--;
    //        if (pageNum >= 1 && pageNum <= pageCount)
    //        {
    //            ViewState["pageNum"] = pageNum;
    //            loadArticle();
    //        }
    //    }

    //}
    protected void all_lbtn_Command(object sender, CommandEventArgs e)
    {
        PagerControl1.LoadData = new LoadDataHandler(this.LoadPagingArticle);
        PagerControl1.PagingParams.TotalCount = total;
        PagerControl1.PagingParams.PageSize = 15;
        PagerControl1.PagingParams.CurrentPageIndex = 0;
        LoadPagingArticle(PagerControl1.PagingParams);
    }
    protected void lb_lbtn_Command(object sender, CommandEventArgs e)
    {
        string leibie = e.CommandName;
        typeBind(leibie);
    }
    protected void loadArticle()
    {

        if (ViewState["pageNum"] != null)
        {
            pnum = Convert.ToInt32(ViewState["pnum"].ToString());
        }
        DataTable dt = BLLArticleInfo.GetFAQlist("15", ((pnum) * 15).ToString());
        this.question_rpt.DataSource = dt;
        this.question_rpt.DataBind();
    }

    protected void typeBind(string lb)
    {

        if (ViewState["pnum"] != null)
        {
            pnum = Convert.ToInt32(ViewState["pnum"].ToString());
        }
        DataTable dt = BLLArticleInfo.GetFAQLB("15", ((pnum) * 15).ToString(), lb, lb);
        this.question_rpt.DataSource = dt;
        this.question_rpt.DataBind();
    }

    protected void confim_ibtn_Command(object sender, CommandEventArgs e)
    {
        //string FAQtitles = this.title_txt.Text;
        //string FAQcontents = this.content_txt.Text;
        //string FAQtypes = this.type_ddl.SelectedValue;
        //string FAQnames = this.name_txt.Text;
        //string FAQmails = this.email_txt.Text;
        //BLLArticleInfo.confimFAQ(FAQtitles, FAQcontents, FAQtypes, FAQnames, FAQmails);
        //Response.Redirect("doctor_online.aspx");
        
        
    }
    private int ii = 5;
    protected void recommend_rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        HtmlControl r = e.Item.FindControl("r") as HtmlControl;
        if (5 / ii == 1)
        {
            //r.Attributes.Add("class", "selected");
        }
        ii--;
    }
    private string GetPagerUrl(int currPageIndex)
    {
        return string.Format("/allergy/doctor/doctor_online.aspx?pnum={0}", currPageIndex);
    }
}

